package com.mall.server.controller.ums;

import com.mall.model.domain.UmsResourceCategory;
import com.mall.model.vo.CommonResult;
import com.mall.server.service.ums.UmsResourceCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author : xyiaao
 * @createDate : 2022/3/31 12:08
 */
@CrossOrigin
@RestController
@RequestMapping("/resourceCategory")
public class UmsResourceCategoryController {


    @Autowired
    private UmsResourceCategoryService umsResourceCategoryService;


    /**
     * 添加后台资源分类
     *
     * @param umsResourceCategory
     * @return
     */
    @PostMapping("/create")
    public CommonResult create(@RequestBody UmsResourceCategory umsResourceCategory) {

        umsResourceCategoryService.create(umsResourceCategory);
        return CommonResult.success();
    }


    /**
     * 根据id删除后台资源分类
     *
     * @param id
     * @return
     */
    @PostMapping("/delete/{id}")
    public CommonResult delete(@PathVariable("id") Integer id) {

        umsResourceCategoryService.delete(id);
        return CommonResult.success();
    }


    /**
     * 查询所有后台资源分类
     *
     * @return
     */
    @GetMapping("/listAll")
    public CommonResult listAll() {

        List<UmsResourceCategory> list = umsResourceCategoryService.listAll();
        return CommonResult.success(list);
    }


    /**
     * 修改后台资源分类
     *
     * @param id
     * @param umsResourceCategory
     * @return
     */
    @PostMapping("/update/{id}")
    public CommonResult update(@PathVariable("id") Integer id, @RequestBody UmsResourceCategory umsResourceCategory) {

        umsResourceCategoryService.update(umsResourceCategory);
        return CommonResult.success();
    }

}
